<?php

//use Phalcon\Mvc\Controller;

require_once APP_PATH . '/app/models/DriverTypeRewardModel.php';

class DrivertyperewardController extends BaseController
{

    function manager_viewAction()
    {
        if ($this->session_timeout) {
            $this->response->redirect('timeout/index');
        } else {
            $this->view->enable();
        }
    }

    function add_viewAction()
    {
        if ($this->session_timeout) {
            $this->response->redirect('timeout/index');
        } else {
            $this->view->enable();
        }
    }

    function circuiteinfo_viewAction()
    {
        if ($this->session_timeout) {
            $this->response->redirect('timeout/index');
        } else {
            $this->view->enable();
        }
    }

    function driversinfo_viewAction()
    {
        if ($this->session_timeout) {
            $this->response->redirect('timeout/index');
        } else {
            $this->view->enable();
        }
    }

    //获取手续费列表
    function glistAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'oc_name' => 'string', //运营名称
            'om_name' => 'string', //车队名称
            'car_NO' => 'string',
            'driver_name' => 'string',
            'driver_phone' => 'string',
            'line_name' => 'string',
            'app' => 'string',
            'start_pos' => 'int',
            'limit' => 'int'
        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->glist($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

    //新增手续费方案
    function addAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'app' => 'string',      //应用来源
            'driver_info' => 'array', //司机信息
            'line_info' => 'array', //线路信息
            'commission_0' => 'numeric',
            'commission_1' => 'numeric',
            'commission_2' => 'numeric',
            'commission_3' => 'numeric'
        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->add($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

    //修改手续费方案
    function modifyAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'id' => 'int',
            'commission_0' => 'numeric',
            'commission_1' => 'numeric',
            'commission_2' => 'numeric',
            'commission_3' => 'numeric'
        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->modify($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

    //删除手续费方案
    function delAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'ids' => 'array',
        );
//        $paramlist = array(
//            'id' => 'int'
//        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->del($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

    //查找司机
    function driverlistAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'om_name' => 'string',
            'car_NO' => 'string',
            'driver_name' => 'string',
            'driver_phone' => 'string',
            'app' => 'string'
        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->driverlist($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

    //查找线路
    function linelistAction()
    {
        if ($this->session_timeout) {
            $this->resp['status'] = -501;
            $this->resp['message'] = 'session timeout!';
            return;
        }

        $paramlist = array(
            'line_name' => 'string',
            'app' => 'string'
        );
        $what = '';
        $p = common::check_json_keys($this->jsdata, $paramlist, $what);
        if (!$p) {
            $this->resp['status'] = -1;
            $this->resp['message'] = $what;
            return;
        }

        $a = new DriverTypeRewardModel();
        $result = $a->linelist($p);
        if (!$result) {
            $this->resp['status'] = last_error_code();
            $this->resp['message'] = last_error_msg();
            return;
        }

        $this->resp = $result;
    }

}
